package com.collect.cameroon.zhiScene.zhiWidget.zhiFilterDaily;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bigkoo.pickerview.builder.OptionsPickerBuilder;
import com.bigkoo.pickerview.builder.TimePickerBuilder;
import com.bigkoo.pickerview.listener.OnOptionsSelectListener;
import com.bigkoo.pickerview.listener.OnTimeSelectListener;
import com.bigkoo.pickerview.view.OptionsPickerView;
import com.bigkoo.pickerview.view.TimePickerView;
import com.collect.cameroon.R;
import com.collect.cameroon.zhiBean.zhiSend.ZHISDailyCaseEntity;
import com.collect.cameroon.zhiScene.zhiWidget.zhiStepView.ZHINextStepView;
import com.collect.cameroon.zhiUtils.StringUtil;
import com.collect.cameroon.zhiUtils.ToastUtil;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

@SuppressLint("NonConstantResourceId")
public class CTFilterDrawerLayout extends LinearLayout implements View.OnClickListener {

    @BindView(R.id.tv_today_all_orders)
    TextView tv_today_all_orders;
    @BindView(R.id.tv_today_new_orders)
    TextView tv_today_new_orders;
    @BindView(R.id.tv_today_repay_orders)
    TextView tv_today_repay_orders;
    @BindView(R.id.tv_no_call)
    TextView tv_no_call;
    @BindView(R.id.tv_call_once)
    TextView tv_call_once;
    @BindView(R.id.tv_call_twice)
    TextView tv_call_twice;

    @BindView(R.id.tv_call_result_ptp)
    TextView tv_call_result_ptp;
    @BindView(R.id.tv_call_result_rnr)
    TextView tv_call_result_rnr;
    @BindView(R.id.tv_call_result_out_of_coverage)
    TextView tv_call_result_out_of_coverage;
    @BindView(R.id.tv_call_result_switched_off)
    TextView tv_call_result_switched_off;
    @BindView(R.id.tv_call_result_innvalid_num)
    TextView tv_call_result_innvalid_num;
    @BindView(R.id.tv_call_result_msg_sent)
    TextView tv_call_result_msg_sent;
    @BindView(R.id.tv_call_result_paid)
    TextView tv_call_result_paid;
    @BindView(R.id.tv_call_result_connected)
    TextView tv_call_result_connected;
    @BindView(R.id.tv_call_result_fake)
    TextView tv_call_result_fake;

    @BindView(R.id.ll_promised_due_time_start)
    LinearLayout ll_promised_due_time_start;
    @BindView(R.id.ll_promised_due_time_end)
    LinearLayout ll_promised_due_time_end;
    @BindView(R.id.tv_promised_due_time_start)
    TextView tv_promised_due_time_start;
    @BindView(R.id.iv_promised_due_time_start_del)
    ImageView iv_promised_due_time_start_del;
    @BindView(R.id.tv_promised_due_time_end)
    TextView tv_promised_due_time_end;
    @BindView(R.id.iv_promised_due_time_end_del)
    ImageView iv_promised_due_time_end_del;

    @BindView(R.id.ll_start_date)
    LinearLayout ll_start_date;
    @BindView(R.id.tv_start_date)
    TextView tv_start_date;
    @BindView(R.id.iv_start_date_del)
    ImageView iv_start_date_del;
    @BindView(R.id.ll_end_date)
    LinearLayout ll_end_date;
    @BindView(R.id.tv_end_date)
    TextView tv_end_date;
    @BindView(R.id.iv_end_date_del)
    ImageView iv_end_date_del;

    @BindView(R.id.ll_more_than)
    LinearLayout ll_more_than;
    @BindView(R.id.tv_more_than)
    TextView tv_more_than;
    @BindView(R.id.iv_more_than_del)
    ImageView iv_more_than_del;
    @BindView(R.id.et_overdue_days)
    EditText et_overdue_days;

    @BindView(R.id.et_user_mobile)
    EditText et_user_mobile;

    @BindView(R.id.btn_combine_query)
    ZHINextStepView btn_combine_query;
    @BindView(R.id.btn_reset)
    ZHINextStepView btn_reset;

    private TimePickerView mPromisedDueTimePickerView;
    private TimePickerView mTimePickerView;
    private OptionsPickerView mOptionsPickerView;
    private Calendar mCalendar = Calendar.getInstance();

    private final Context mContext;
    private View mView;

    private boolean mIsPromisedDueStartDatePicker = false;
    private boolean mIsStartDatePicker = false;
    private List<String> mOptionList;

    private String mParamsTodayOrder = getResources().getString(R.string.today_all_orders);
    private String mParamsCallCount = getResources().getString(R.string.no_call);
    private String mParamsCallResult = "";
    private String mParamsStartDate = "";
    private String mParamsEndDate = "";
    private String mParamsOverdueQueryType = "";
    private String mParamsOverdueDays = "";
    private String mParamsMobile = "";
    private String mParamsPromisedDueStartDate = "";
    private String mParamsPromisedDueEndDate = "";

    private OnFilterClickListener mOnFilterClickListener;

    public CTFilterDrawerLayout(Context context) {
        this(context, null);
    }

    public CTFilterDrawerLayout(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public CTFilterDrawerLayout(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);

        this.mContext = context;

        initContentView();
        initView();
    }

    @SuppressLint("SetTextI18n")
    private void initContentView() {
        mView = View.inflate(mContext, R.layout.drawer_layout_main, this);
        ButterKnife.bind(this);

        mOptionList = new ArrayList<String>();
        mOptionList.add(mContext.getResources().getString(R.string.more_than));
        mOptionList.add(mContext.getResources().getString(R.string.equal));
        mOptionList.add(mContext.getResources().getString(R.string.less_than));
        initOptionsPickerView();

        mTimePickerView = showDatePicker(mContext);
        mPromisedDueTimePickerView = showPromisedDueDatePicker(mContext);
        tv_today_new_orders.setText("Today" + "\'" + "s new order");

        tv_today_all_orders.setOnClickListener(this);
        tv_today_new_orders.setOnClickListener(this);
        tv_today_repay_orders.setOnClickListener(this);
        tv_no_call.setOnClickListener(this);
        tv_call_once.setOnClickListener(this);
        tv_call_twice.setOnClickListener(this);

        tv_call_result_ptp.setOnClickListener(this);
        tv_call_result_rnr.setOnClickListener(this);
        tv_call_result_switched_off.setOnClickListener(this);
        tv_call_result_innvalid_num.setOnClickListener(this);
        tv_call_result_out_of_coverage.setOnClickListener(this);
        tv_call_result_msg_sent.setOnClickListener(this);
        tv_call_result_paid.setOnClickListener(this);
        tv_call_result_connected.setOnClickListener(this);
        tv_call_result_fake.setOnClickListener(this);

        tv_promised_due_time_start.setOnClickListener(this);
        tv_promised_due_time_end.setOnClickListener(this);
        iv_promised_due_time_start_del.setOnClickListener(this);
        iv_promised_due_time_end_del.setOnClickListener(this);

        tv_start_date.setOnClickListener(this);
        iv_start_date_del.setOnClickListener(this);
        tv_end_date.setOnClickListener(this);
        iv_end_date_del.setOnClickListener(this);

        tv_more_than.setOnClickListener(this);
        iv_more_than_del.setOnClickListener(this);
    }

    // 初始化页面，根据设置项显示
    private void initView() {
        btn_combine_query.setOnMenuItemDidChangedListener(item -> {
            try {
                if (mOnFilterClickListener != null) {
                    ZHISDailyCaseEntity zhisDailyCaseEntity = getFilterResults();
                    if (zhisDailyCaseEntity == null) {
                        return;
                    }
                    mOnFilterClickListener.onFilterClick(true, zhisDailyCaseEntity);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        });
        btn_reset.setOnMenuItemDidChangedListener(item -> resetUI());
    }

    @SuppressLint("UseCompatLoadingForDrawables")
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_today_all_orders: {
                String qtext = tv_today_all_orders.getText().toString().trim();
                if (StringUtil.safeString(mParamsTodayOrder).equalsIgnoreCase(qtext)) {
                    mParamsTodayOrder = "";
                    tv_today_all_orders.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                    tv_today_all_orders.setTextColor(getResources().getColor(R.color.theme_black_2));
                } else {
                    mParamsTodayOrder = qtext;
                    tv_today_all_orders.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_color_0_corners_4dp));
                    tv_today_all_orders.setTextColor(getResources().getColor(R.color.white));
                }

                tv_today_new_orders.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                tv_today_new_orders.setTextColor(getResources().getColor(R.color.theme_black_2));

                tv_today_repay_orders.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                tv_today_repay_orders.setTextColor(getResources().getColor(R.color.theme_black_2));
                break;
            }
            case R.id.tv_today_new_orders: {
                String qtext = tv_today_new_orders.getText().toString().trim();
                if (StringUtil.safeString(mParamsTodayOrder).equalsIgnoreCase(qtext)) {
                    mParamsTodayOrder = "";
                    tv_today_new_orders.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                    tv_today_new_orders.setTextColor(getResources().getColor(R.color.theme_black_2));
                } else {
                    mParamsTodayOrder = qtext;
                    tv_today_new_orders.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_color_0_corners_4dp));
                    tv_today_new_orders.setTextColor(getResources().getColor(R.color.white));
                }

                tv_today_all_orders.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                tv_today_all_orders.setTextColor(getResources().getColor(R.color.theme_black_2));

                tv_today_repay_orders.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                tv_today_repay_orders.setTextColor(getResources().getColor(R.color.theme_black_2));
                break;
            }
            case R.id.tv_today_repay_orders: {
                String qtext = tv_today_repay_orders.getText().toString().trim();
                if (StringUtil.safeString(mParamsTodayOrder).equalsIgnoreCase(qtext)) {
                    mParamsTodayOrder = "";
                    tv_today_repay_orders.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                    tv_today_repay_orders.setTextColor(getResources().getColor(R.color.theme_black_2));
                } else {
                    mParamsTodayOrder = qtext;
                    tv_today_repay_orders.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_color_0_corners_4dp));
                    tv_today_repay_orders.setTextColor(getResources().getColor(R.color.white));
                }

                tv_today_all_orders.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                tv_today_all_orders.setTextColor(getResources().getColor(R.color.theme_black_2));

                tv_today_new_orders.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                tv_today_new_orders.setTextColor(getResources().getColor(R.color.theme_black_2));
                break;
            }
            case R.id.tv_no_call: {
                String qtext = tv_no_call.getText().toString().trim();
                if (StringUtil.safeString(mParamsCallCount).equalsIgnoreCase(qtext)) {
                    mParamsCallCount = "";
                    tv_no_call.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                    tv_no_call.setTextColor(getResources().getColor(R.color.theme_black_2));
                } else {
                    mParamsCallCount = qtext;
                    tv_no_call.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_color_0_corners_4dp));
                    tv_no_call.setTextColor(getResources().getColor(R.color.white));
                }

                tv_call_once.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                tv_call_once.setTextColor(getResources().getColor(R.color.theme_black_2));

                tv_call_twice.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                tv_call_twice.setTextColor(getResources().getColor(R.color.theme_black_2));
                break;
            }
            case R.id.tv_call_once: {
                String qtext = tv_call_once.getText().toString().trim();
                if (StringUtil.safeString(mParamsCallCount).equalsIgnoreCase(qtext)) {
                    mParamsCallCount = "";
                    tv_call_once.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                    tv_call_once.setTextColor(getResources().getColor(R.color.theme_black_2));
                } else {
                    mParamsCallCount = qtext;
                    tv_call_once.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_color_0_corners_4dp));
                    tv_call_once.setTextColor(getResources().getColor(R.color.white));
                }

                tv_no_call.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                tv_no_call.setTextColor(getResources().getColor(R.color.theme_black_2));

                tv_call_twice.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                tv_call_twice.setTextColor(getResources().getColor(R.color.theme_black_2));
                break;
            }
            case R.id.tv_call_twice: {
                String qtext = tv_call_twice.getText().toString().trim();
                if (StringUtil.safeString(mParamsCallCount).equalsIgnoreCase(qtext)) {
                    mParamsCallCount = "";
                    tv_call_twice.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                    tv_call_twice.setTextColor(getResources().getColor(R.color.theme_black_2));
                } else {
                    mParamsCallCount = qtext;
                    tv_call_twice.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_color_0_corners_4dp));
                    tv_call_twice.setTextColor(getResources().getColor(R.color.white));
                }

                tv_no_call.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                tv_no_call.setTextColor(getResources().getColor(R.color.theme_black_2));

                tv_call_once.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                tv_call_once.setTextColor(getResources().getColor(R.color.theme_black_2));
                break;
            }
            case R.id.tv_call_result_ptp: {
                String qtext = tv_call_result_ptp.getText().toString().trim();
                if (StringUtil.safeString(mParamsCallResult).equalsIgnoreCase(qtext)) {
                    mParamsCallResult = "";
                    tv_call_result_ptp.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                    tv_call_result_ptp.setTextColor(getResources().getColor(R.color.theme_black_2));
                } else {
                    mParamsCallResult = qtext;
                    tv_call_result_ptp.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_color_0_corners_4dp));
                    tv_call_result_ptp.setTextColor(getResources().getColor(R.color.white));
                }

                tv_call_result_rnr.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                tv_call_result_rnr.setTextColor(getResources().getColor(R.color.theme_black_2));

                tv_call_result_switched_off.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                tv_call_result_switched_off.setTextColor(getResources().getColor(R.color.theme_black_2));

                tv_call_result_innvalid_num.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                tv_call_result_innvalid_num.setTextColor(getResources().getColor(R.color.theme_black_2));

                tv_call_result_out_of_coverage.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                tv_call_result_out_of_coverage.setTextColor(getResources().getColor(R.color.theme_black_2));

                tv_call_result_msg_sent.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                tv_call_result_msg_sent.setTextColor(getResources().getColor(R.color.theme_black_2));

                tv_call_result_paid.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                tv_call_result_paid.setTextColor(getResources().getColor(R.color.theme_black_2));

                tv_call_result_connected.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                tv_call_result_connected.setTextColor(getResources().getColor(R.color.theme_black_2));

                tv_call_result_fake.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                tv_call_result_fake.setTextColor(getResources().getColor(R.color.theme_black_2));
                break;
            }
            case R.id.tv_call_result_rnr: {
                String qtext = tv_call_result_rnr.getText().toString().trim();
                if (StringUtil.safeString(mParamsCallResult).equalsIgnoreCase(qtext)) {
                    mParamsCallResult = "";
                    tv_call_result_rnr.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                    tv_call_result_rnr.setTextColor(getResources().getColor(R.color.theme_black_2));
                } else {
                    mParamsCallResult = qtext;
                    tv_call_result_rnr.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_color_0_corners_4dp));
                    tv_call_result_rnr.setTextColor(getResources().getColor(R.color.white));
                }

                tv_call_result_ptp.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                tv_call_result_ptp.setTextColor(getResources().getColor(R.color.theme_black_2));

                tv_call_result_switched_off.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                tv_call_result_switched_off.setTextColor(getResources().getColor(R.color.theme_black_2));

                tv_call_result_innvalid_num.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                tv_call_result_innvalid_num.setTextColor(getResources().getColor(R.color.theme_black_2));

                tv_call_result_out_of_coverage.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                tv_call_result_out_of_coverage.setTextColor(getResources().getColor(R.color.theme_black_2));

                tv_call_result_msg_sent.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                tv_call_result_msg_sent.setTextColor(getResources().getColor(R.color.theme_black_2));

                tv_call_result_paid.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                tv_call_result_paid.setTextColor(getResources().getColor(R.color.theme_black_2));

                tv_call_result_connected.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                tv_call_result_connected.setTextColor(getResources().getColor(R.color.theme_black_2));

                tv_call_result_fake.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                tv_call_result_fake.setTextColor(getResources().getColor(R.color.theme_black_2));
                break;
            }
            case R.id.tv_call_result_switched_off: {
                String qtext = tv_call_result_switched_off.getText().toString().trim();
                if (StringUtil.safeString(mParamsCallResult).equalsIgnoreCase(qtext)) {
                    mParamsCallResult = "";
                    tv_call_result_switched_off.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                    tv_call_result_switched_off.setTextColor(getResources().getColor(R.color.theme_black_2));
                } else {
                    mParamsCallResult = qtext;
                    tv_call_result_switched_off.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_color_0_corners_4dp));
                    tv_call_result_switched_off.setTextColor(getResources().getColor(R.color.white));
                }

                tv_call_result_ptp.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                tv_call_result_ptp.setTextColor(getResources().getColor(R.color.theme_black_2));

                tv_call_result_rnr.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                tv_call_result_rnr.setTextColor(getResources().getColor(R.color.theme_black_2));

                tv_call_result_innvalid_num.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                tv_call_result_innvalid_num.setTextColor(getResources().getColor(R.color.theme_black_2));

                tv_call_result_out_of_coverage.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                tv_call_result_out_of_coverage.setTextColor(getResources().getColor(R.color.theme_black_2));

                tv_call_result_msg_sent.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                tv_call_result_msg_sent.setTextColor(getResources().getColor(R.color.theme_black_2));

                tv_call_result_paid.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                tv_call_result_paid.setTextColor(getResources().getColor(R.color.theme_black_2));

                tv_call_result_connected.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                tv_call_result_connected.setTextColor(getResources().getColor(R.color.theme_black_2));

                tv_call_result_fake.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                tv_call_result_fake.setTextColor(getResources().getColor(R.color.theme_black_2));
                break;
            }
            case R.id.tv_call_result_innvalid_num: {
                String qtext = tv_call_result_innvalid_num.getText().toString().trim();
                if (StringUtil.safeString(mParamsCallResult).equalsIgnoreCase(qtext)) {
                    mParamsCallResult = "";
                    tv_call_result_innvalid_num.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                    tv_call_result_innvalid_num.setTextColor(getResources().getColor(R.color.theme_black_2));
                } else {
                    mParamsCallResult = qtext;
                    tv_call_result_innvalid_num.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_color_0_corners_4dp));
                    tv_call_result_innvalid_num.setTextColor(getResources().getColor(R.color.white));
                }

                tv_call_result_ptp.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                tv_call_result_ptp.setTextColor(getResources().getColor(R.color.theme_black_2));

                tv_call_result_rnr.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                tv_call_result_rnr.setTextColor(getResources().getColor(R.color.theme_black_2));

                tv_call_result_switched_off.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                tv_call_result_switched_off.setTextColor(getResources().getColor(R.color.theme_black_2));

                tv_call_result_out_of_coverage.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                tv_call_result_out_of_coverage.setTextColor(getResources().getColor(R.color.theme_black_2));

                tv_call_result_msg_sent.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                tv_call_result_msg_sent.setTextColor(getResources().getColor(R.color.theme_black_2));

                tv_call_result_paid.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                tv_call_result_paid.setTextColor(getResources().getColor(R.color.theme_black_2));

                tv_call_result_connected.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                tv_call_result_connected.setTextColor(getResources().getColor(R.color.theme_black_2));

                tv_call_result_fake.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                tv_call_result_fake.setTextColor(getResources().getColor(R.color.theme_black_2));
                break;
            }
            case R.id.tv_call_result_out_of_coverage: {
                String qtext = tv_call_result_out_of_coverage.getText().toString().trim();
                if (StringUtil.safeString(mParamsCallResult).equalsIgnoreCase(qtext)) {
                    mParamsCallResult = "";
                    tv_call_result_out_of_coverage.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                    tv_call_result_out_of_coverage.setTextColor(getResources().getColor(R.color.theme_black_2));
                } else {
                    mParamsCallResult = qtext;
                    tv_call_result_out_of_coverage.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_color_0_corners_4dp));
                    tv_call_result_out_of_coverage.setTextColor(getResources().getColor(R.color.white));
                }

                tv_call_result_ptp.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                tv_call_result_ptp.setTextColor(getResources().getColor(R.color.theme_black_2));

                tv_call_result_rnr.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                tv_call_result_rnr.setTextColor(getResources().getColor(R.color.theme_black_2));

                tv_call_result_switched_off.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                tv_call_result_switched_off.setTextColor(getResources().getColor(R.color.theme_black_2));

                tv_call_result_innvalid_num.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                tv_call_result_innvalid_num.setTextColor(getResources().getColor(R.color.theme_black_2));

                tv_call_result_msg_sent.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                tv_call_result_msg_sent.setTextColor(getResources().getColor(R.color.theme_black_2));

                tv_call_result_paid.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                tv_call_result_paid.setTextColor(getResources().getColor(R.color.theme_black_2));

                tv_call_result_connected.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                tv_call_result_connected.setTextColor(getResources().getColor(R.color.theme_black_2));

                tv_call_result_fake.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                tv_call_result_fake.setTextColor(getResources().getColor(R.color.theme_black_2));
                break;
            }
            case R.id.tv_call_result_msg_sent: {
                String qtext = tv_call_result_msg_sent.getText().toString().trim();
                if (StringUtil.safeString(mParamsCallResult).equalsIgnoreCase(qtext)) {
                    mParamsCallResult = "";
                    tv_call_result_msg_sent.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                    tv_call_result_msg_sent.setTextColor(getResources().getColor(R.color.theme_black_2));
                } else {
                    mParamsCallResult = qtext;
                    tv_call_result_msg_sent.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_color_0_corners_4dp));
                    tv_call_result_msg_sent.setTextColor(getResources().getColor(R.color.white));
                }

                tv_call_result_ptp.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                tv_call_result_ptp.setTextColor(getResources().getColor(R.color.theme_black_2));

                tv_call_result_rnr.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                tv_call_result_rnr.setTextColor(getResources().getColor(R.color.theme_black_2));

                tv_call_result_switched_off.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                tv_call_result_switched_off.setTextColor(getResources().getColor(R.color.theme_black_2));

                tv_call_result_innvalid_num.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                tv_call_result_innvalid_num.setTextColor(getResources().getColor(R.color.theme_black_2));

                tv_call_result_out_of_coverage.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                tv_call_result_out_of_coverage.setTextColor(getResources().getColor(R.color.theme_black_2));

                tv_call_result_paid.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                tv_call_result_paid.setTextColor(getResources().getColor(R.color.theme_black_2));

                tv_call_result_connected.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                tv_call_result_connected.setTextColor(getResources().getColor(R.color.theme_black_2));

                tv_call_result_fake.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                tv_call_result_fake.setTextColor(getResources().getColor(R.color.theme_black_2));
                break;
            }
            case R.id.tv_call_result_paid: {
                String qtext = tv_call_result_paid.getText().toString().trim();
                if (StringUtil.safeString(mParamsCallResult).equalsIgnoreCase(qtext)) {
                    mParamsCallResult = "";
                    tv_call_result_paid.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                    tv_call_result_paid.setTextColor(getResources().getColor(R.color.theme_black_2));
                } else {
                    mParamsCallResult = qtext;
                    tv_call_result_paid.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_color_0_corners_4dp));
                    tv_call_result_paid.setTextColor(getResources().getColor(R.color.white));
                }

                tv_call_result_ptp.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                tv_call_result_ptp.setTextColor(getResources().getColor(R.color.theme_black_2));

                tv_call_result_rnr.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                tv_call_result_rnr.setTextColor(getResources().getColor(R.color.theme_black_2));

                tv_call_result_switched_off.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                tv_call_result_switched_off.setTextColor(getResources().getColor(R.color.theme_black_2));

                tv_call_result_innvalid_num.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                tv_call_result_innvalid_num.setTextColor(getResources().getColor(R.color.theme_black_2));

                tv_call_result_out_of_coverage.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                tv_call_result_out_of_coverage.setTextColor(getResources().getColor(R.color.theme_black_2));

                tv_call_result_connected.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                tv_call_result_connected.setTextColor(getResources().getColor(R.color.theme_black_2));

                tv_call_result_fake.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                tv_call_result_fake.setTextColor(getResources().getColor(R.color.theme_black_2));
                break;
            }
            case R.id.tv_call_result_connected: {
                String qtext = tv_call_result_connected.getText().toString().trim();
                if (StringUtil.safeString(mParamsCallResult).equalsIgnoreCase(qtext)) {
                    mParamsCallResult = "";
                    tv_call_result_connected.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                    tv_call_result_connected.setTextColor(getResources().getColor(R.color.theme_black_2));
                } else {
                    mParamsCallResult = qtext;
                    tv_call_result_connected.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_color_0_corners_4dp));
                    tv_call_result_connected.setTextColor(getResources().getColor(R.color.white));
                }

                tv_call_result_ptp.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                tv_call_result_ptp.setTextColor(getResources().getColor(R.color.theme_black_2));

                tv_call_result_rnr.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                tv_call_result_rnr.setTextColor(getResources().getColor(R.color.theme_black_2));

                tv_call_result_switched_off.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                tv_call_result_switched_off.setTextColor(getResources().getColor(R.color.theme_black_2));

                tv_call_result_innvalid_num.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                tv_call_result_innvalid_num.setTextColor(getResources().getColor(R.color.theme_black_2));

                tv_call_result_out_of_coverage.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                tv_call_result_out_of_coverage.setTextColor(getResources().getColor(R.color.theme_black_2));

                tv_call_result_paid.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                tv_call_result_paid.setTextColor(getResources().getColor(R.color.theme_black_2));

                tv_call_result_fake.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                tv_call_result_fake.setTextColor(getResources().getColor(R.color.theme_black_2));
                break;
            }
            case R.id.tv_call_result_fake: {
                String qtext = tv_call_result_fake.getText().toString().trim();
                if (StringUtil.safeString(mParamsCallResult).equalsIgnoreCase(qtext)) {
                    mParamsCallResult = "";
                    tv_call_result_fake.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                    tv_call_result_fake.setTextColor(getResources().getColor(R.color.theme_black_2));
                } else {
                    mParamsCallResult = qtext;
                    tv_call_result_fake.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_color_0_corners_4dp));
                    tv_call_result_fake.setTextColor(getResources().getColor(R.color.white));
                }

                tv_call_result_ptp.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                tv_call_result_ptp.setTextColor(getResources().getColor(R.color.theme_black_2));

                tv_call_result_rnr.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                tv_call_result_rnr.setTextColor(getResources().getColor(R.color.theme_black_2));

                tv_call_result_switched_off.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                tv_call_result_switched_off.setTextColor(getResources().getColor(R.color.theme_black_2));

                tv_call_result_innvalid_num.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                tv_call_result_innvalid_num.setTextColor(getResources().getColor(R.color.theme_black_2));

                tv_call_result_out_of_coverage.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                tv_call_result_out_of_coverage.setTextColor(getResources().getColor(R.color.theme_black_2));

                tv_call_result_paid.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                tv_call_result_paid.setTextColor(getResources().getColor(R.color.theme_black_2));

                tv_call_result_connected.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                tv_call_result_connected.setTextColor(getResources().getColor(R.color.theme_black_2));
                break;
            }
            case R.id.tv_promised_due_time_start: {
                mIsPromisedDueStartDatePicker = true;
                mPromisedDueTimePickerView.show();
                break;
            }
            case R.id.iv_promised_due_time_start_del: {
                if (tv_promised_due_time_start.getText().toString().trim().startsWith(mContext.getString(R.string.start_date))) {
                    mIsPromisedDueStartDatePicker = true;
                    mPromisedDueTimePickerView.show();
                    break;
                }
                mParamsPromisedDueStartDate = "";
                iv_promised_due_time_start_del.setImageResource(R.drawable.cf_ic_cf_37);
                tv_promised_due_time_start.setText(mContext.getResources().getString(R.string.start_date));
                tv_promised_due_time_start.setTextColor(getResources().getColor(R.color.theme_black_2));
                ll_promised_due_time_start.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                break;
            }
            case R.id.tv_promised_due_time_end: {
                mIsPromisedDueStartDatePicker = false;
                mPromisedDueTimePickerView.show();
                break;
            }
            case R.id.iv_promised_due_time_end_del: {
                if (tv_promised_due_time_end.getText().toString().trim().startsWith(mContext.getString(R.string.start_date))) {
                    mIsPromisedDueStartDatePicker = false;
                    mPromisedDueTimePickerView.show();
                    break;
                }
                mParamsPromisedDueEndDate = "";
                iv_promised_due_time_end_del.setImageResource(R.drawable.cf_ic_cf_37);
                tv_promised_due_time_end.setText(mContext.getResources().getString(R.string.end_date));
                tv_promised_due_time_end.setTextColor(getResources().getColor(R.color.theme_black_2));
                ll_promised_due_time_end.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                break;
            }
            case R.id.tv_start_date: {
                mIsStartDatePicker = true;
                mTimePickerView.show();
                break;
            }
            case R.id.iv_start_date_del: {
                if (tv_start_date.getText().toString().trim().startsWith(mContext.getString(R.string.start_date))) {
                    mIsStartDatePicker = true;
                    mTimePickerView.show();
                    break;
                }
                mParamsStartDate = "";
                iv_start_date_del.setImageResource(R.drawable.cf_ic_cf_37);
                tv_start_date.setText(mContext.getResources().getString(R.string.start_date));
                tv_start_date.setTextColor(getResources().getColor(R.color.theme_black_2));
                ll_start_date.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                break;
            }
            case R.id.tv_end_date: {
                mIsStartDatePicker = false;
                mTimePickerView.show();
                break;
            }
            case R.id.iv_end_date_del: {
                if (tv_end_date.getText().toString().trim().startsWith(mContext.getString(R.string.end_date))) {
                    mIsStartDatePicker = false;
                    mTimePickerView.show();
                    break;
                }
                mParamsEndDate = "";
                iv_end_date_del.setImageResource(R.drawable.cf_ic_cf_37);
                tv_end_date.setText(mContext.getResources().getString(R.string.end_date));
                tv_end_date.setTextColor(getResources().getColor(R.color.theme_black_2));
                ll_end_date.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                break;
            }
            case R.id.tv_more_than: {
                mOptionsPickerView.show();
                break;
            }
            case R.id.iv_more_than_del: {
                if (tv_more_than.getText().toString().trim().startsWith("Sel")) {
                    mOptionsPickerView.show();
                    break;
                }
                mParamsOverdueQueryType = "";
                iv_more_than_del.setImageResource(R.drawable.cf_ic_cf_37);
                tv_more_than.setText(mContext.getResources().getString(R.string.compare));
                tv_more_than.setTextColor(getResources().getColor(R.color.theme_black_2));
                ll_more_than.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
                break;
            }
        }
    }

    public CTFilterDrawerLayout setFilterClickListener(OnFilterClickListener filterClickListener) {
        this.mOnFilterClickListener = filterClickListener;
        return this;
    }

    public CTFilterDrawerLayout setStartDate(String startDate) {
        if (!TextUtils.isEmpty(startDate)) {
            tv_start_date.setText(startDate);
        }
        return this;
    }

    public CTFilterDrawerLayout setEndDate(String endDate) {
        if (!TextUtils.isEmpty(endDate)) {
            tv_end_date.setText(endDate);
        }
        return this;
    }

    public void setParentView(Context context) {

    }

    public interface OnFilterClickListener {
        void onFilterClick(boolean shouldRefresh, ZHISDailyCaseEntity zhisDailyCaseEntity);
    }

    @SuppressLint("UseCompatLoadingForDrawables")
    private void resetUI() {
        mParamsTodayOrder = getResources().getString(R.string.today_all_orders);
        mParamsCallCount = getResources().getString(R.string.no_call);
        mParamsCallResult = "";
        mParamsStartDate = "";
        mParamsEndDate = "";
        mParamsOverdueQueryType = "";
        mParamsOverdueDays = "";
        mParamsMobile = "";
        mParamsPromisedDueStartDate = "";
        mParamsPromisedDueEndDate = "";

        /////////////////////////
        tv_today_all_orders.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_color_0_corners_4dp));
        tv_today_all_orders.setTextColor(getResources().getColor(R.color.white));

        tv_today_new_orders.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
        tv_today_new_orders.setTextColor(getResources().getColor(R.color.theme_black_2));

        tv_today_repay_orders.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
        tv_today_repay_orders.setTextColor(getResources().getColor(R.color.theme_black_2));


        /////////////////////////
        tv_no_call.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_color_0_corners_4dp));
        tv_no_call.setTextColor(getResources().getColor(R.color.white));

        tv_call_once.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
        tv_call_once.setTextColor(getResources().getColor(R.color.theme_black_2));

        tv_call_twice.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
        tv_call_twice.setTextColor(getResources().getColor(R.color.theme_black_2));


        /////////////////////////
        tv_call_result_ptp.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
        tv_call_result_ptp.setTextColor(getResources().getColor(R.color.theme_black_2));

        tv_call_result_rnr.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
        tv_call_result_rnr.setTextColor(getResources().getColor(R.color.theme_black_2));

        tv_call_result_switched_off.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
        tv_call_result_switched_off.setTextColor(getResources().getColor(R.color.theme_black_2));

        tv_call_result_innvalid_num.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
        tv_call_result_innvalid_num.setTextColor(getResources().getColor(R.color.theme_black_2));

        tv_call_result_out_of_coverage.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
        tv_call_result_out_of_coverage.setTextColor(getResources().getColor(R.color.theme_black_2));

        tv_call_result_msg_sent.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
        tv_call_result_msg_sent.setTextColor(getResources().getColor(R.color.theme_black_2));

        tv_call_result_paid.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
        tv_call_result_paid.setTextColor(getResources().getColor(R.color.theme_black_2));

        tv_call_result_connected.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
        tv_call_result_connected.setTextColor(getResources().getColor(R.color.theme_black_2));

        tv_call_result_fake.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));
        tv_call_result_fake.setTextColor(getResources().getColor(R.color.theme_black_2));


        /////////////////////////
        iv_promised_due_time_start_del.setImageResource(R.drawable.cf_ic_cf_37);
        tv_promised_due_time_start.setText(mContext.getResources().getString(R.string.start_date));
        tv_promised_due_time_start.setTextColor(getResources().getColor(R.color.theme_black_2));
        ll_promised_due_time_start.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));

        /////////////////////////
        iv_promised_due_time_end_del.setImageResource(R.drawable.cf_ic_cf_37);
        tv_promised_due_time_end.setText(mContext.getResources().getString(R.string.start_date));
        tv_promised_due_time_end.setTextColor(getResources().getColor(R.color.theme_black_2));
        ll_promised_due_time_end.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));

        /////////////////////////
        iv_start_date_del.setImageResource(R.drawable.cf_ic_cf_37);
        tv_start_date.setText(mContext.getResources().getString(R.string.start_date));
        tv_start_date.setTextColor(getResources().getColor(R.color.theme_black_2));
        ll_start_date.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));


        /////////////////////////
        iv_end_date_del.setImageResource(R.drawable.cf_ic_cf_37);
        tv_end_date.setText(mContext.getResources().getString(R.string.end_date));
        tv_end_date.setTextColor(getResources().getColor(R.color.theme_black_2));
        ll_end_date.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));


        /////////////////////////
        iv_more_than_del.setImageResource(R.drawable.cf_ic_cf_37);
        tv_more_than.setText(mContext.getResources().getString(R.string.compare));
        tv_more_than.setTextColor(getResources().getColor(R.color.theme_black_2));
        ll_more_than.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_black_4_corners_4dp));


        /////////////////////////
        et_overdue_days.setText("");


        /////////////////////////
        et_user_mobile.setText("");

    }

    @SuppressLint("SimpleDateFormat,SetTextI18n")
    private TimePickerView showPromisedDueDatePicker(Context context) {
        @SuppressLint("UseCompatLoadingForDrawables") OnTimeSelectListener mOnTimeSelectListener = (date, v) -> {
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
            String dateString = format.format(date);
            if (mIsPromisedDueStartDatePicker) {
                //cf_ic_cf_113
                mParamsPromisedDueStartDate = dateString;
                iv_promised_due_time_start_del.setImageResource(R.drawable.cf_ic_cf_113);
                tv_promised_due_time_start.setText(dateString);
                tv_promised_due_time_start.setTextColor(getResources().getColor(R.color.white));
                ll_promised_due_time_start.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_color_0_corners_4dp));
            } else {
                mParamsPromisedDueEndDate = dateString;
                iv_promised_due_time_end_del.setImageResource(R.drawable.cf_ic_cf_113);
                tv_promised_due_time_end.setText(dateString);
                tv_promised_due_time_end.setTextColor(getResources().getColor(R.color.white));
                ll_promised_due_time_end.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_color_0_corners_4dp));
            }
        };

        Calendar startCalendar = Calendar.getInstance();
        startCalendar.set(2021, 1, 15);
        Calendar endCalendar = Calendar.getInstance();
        endCalendar.set(2030, 9, 15);
        TimePickerView pvTime = new TimePickerBuilder(context, mOnTimeSelectListener)
                .setType(new boolean[]{true, true, true, true, true, false})
                .setCancelText(" ")
                .setContentTextSize(18)
                .setTitleSize(20)
                .setTitleText("")
                .setTitleBgColor(context.getResources().getColor(R.color.theme_blue_4))
                .setTextColorCenter(context.getResources().getColor(R.color.theme_black_0))
                .setOutSideCancelable(true)
                .setRangDate(startCalendar, endCalendar)
                .setTitleColor(context.getResources().getColor(R.color.theme_black_0))
                .setCancelColor(context.getResources().getColor(R.color.white))
                .setSubmitColor(context.getResources().getColor(R.color.white))
                .isDialog(true)
                .build();

        Dialog mDialog = pvTime.getDialog();
        if (mDialog != null) {
            FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(
                    ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT,
                    Gravity.BOTTOM);

            params.leftMargin = 0;
            params.rightMargin = 0;
            pvTime.getDialogContainerLayout().setLayoutParams(params);

            Window dialogWindow = mDialog.getWindow();
            if (dialogWindow != null) {
                dialogWindow.setWindowAnimations(com.bigkoo.pickerview.R.style.picker_view_slide_anim);
                dialogWindow.setGravity(Gravity.BOTTOM);
                dialogWindow.setDimAmount(0.3f);
            }
        }

        return pvTime;
    }

    @SuppressLint("SimpleDateFormat,SetTextI18n")
    private TimePickerView showDatePicker(Context context) {
        @SuppressLint("UseCompatLoadingForDrawables") OnTimeSelectListener mOnTimeSelectListener = (date, v) -> {
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
            format.format(date);
            mCalendar.setTime(date);
            int gYear = mCalendar.get(Calendar.YEAR);
            int gMonth = (mCalendar.get(Calendar.MONTH) + 1);
            int gDay = mCalendar.get(Calendar.DAY_OF_MONTH);
            String dateString = (gYear + "-" + gMonth + "-" + gDay);

            if (mIsStartDatePicker) {
                //cf_ic_cf_113
                mParamsStartDate = dateString;
                iv_start_date_del.setImageResource(R.drawable.cf_ic_cf_113);
                tv_start_date.setText(gYear + "-" + gMonth + "-" + gDay);
                tv_start_date.setTextColor(getResources().getColor(R.color.white));
                ll_start_date.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_color_0_corners_4dp));
            } else {
                mParamsEndDate = dateString;
                iv_end_date_del.setImageResource(R.drawable.cf_ic_cf_113);
                tv_end_date.setText(gYear + "-" + gMonth + "-" + gDay);
                tv_end_date.setTextColor(getResources().getColor(R.color.white));
                ll_end_date.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_color_0_corners_4dp));
            }
        };

        Calendar startCalendar = Calendar.getInstance();
        startCalendar.set(2020, 9, 15);
        Calendar endCalendar = Calendar.getInstance();
        endCalendar.set(2030, 9, 15);
        TimePickerView pvTime = new TimePickerBuilder(context, mOnTimeSelectListener)
                .setType(new boolean[]{true, true, true, false, false, false})
                .setCancelText(" ")
                .setContentTextSize(18)
                .setTitleSize(20)
                .setTitleText("")
                .setTitleBgColor(context.getResources().getColor(R.color.theme_blue_4))
                .setTextColorCenter(context.getResources().getColor(R.color.theme_black_0))
                .setOutSideCancelable(true)
                .setRangDate(startCalendar, endCalendar)
                .setTitleColor(context.getResources().getColor(R.color.theme_black_0))
                .setCancelColor(context.getResources().getColor(R.color.white))
                .setSubmitColor(context.getResources().getColor(R.color.white))
                .isDialog(true)
                .build();

        Dialog mDialog = pvTime.getDialog();
        if (mDialog != null) {
            FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(
                    ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT,
                    Gravity.BOTTOM);

            params.leftMargin = 0;
            params.rightMargin = 0;
            pvTime.getDialogContainerLayout().setLayoutParams(params);

            Window dialogWindow = mDialog.getWindow();
            if (dialogWindow != null) {
                dialogWindow.setWindowAnimations(com.bigkoo.pickerview.R.style.picker_view_slide_anim);
                dialogWindow.setGravity(Gravity.BOTTOM);
                dialogWindow.setDimAmount(0.3f);
            }
        }

        return pvTime;
    }

    private void initOptionsPickerView() {

        OnOptionsSelectListener mOnOptionsSelectListener = new OnOptionsSelectListener() {
            @SuppressLint("UseCompatLoadingForDrawables")
            @Override
            public void onOptionsSelect(int options1, int options2, int options3, View v) {
                try {
                    String content = StringUtil.safeString(mOptionList.get(options1));
                    mParamsOverdueQueryType = content;
                    tv_more_than.setText(content);
                    tv_more_than.setTextColor(getResources().getColor(R.color.white));
                    ll_more_than.setBackground(getResources().getDrawable(R.drawable.bg_solid_theme_color_0_corners_4dp));
                    iv_more_than_del.setImageResource(R.drawable.cf_ic_cf_113);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        };

        mOptionsPickerView = new OptionsPickerBuilder(mContext, mOnOptionsSelectListener)
                .setTitleText("")
                .setContentTextSize(20)
                .setDividerColor(Color.LTGRAY)
                .setSelectOptions(0)
                .setBgColor(Color.WHITE)
                .setTitleBgColor(mContext.getResources().getColor(R.color.theme_color_0))
                .setTitleColor(mContext.getResources().getColor(R.color.theme_black_0))
                .setCancelText(" ")
                .setCancelColor(mContext.getResources().getColor(R.color.white))
                .setSubmitColor(mContext.getResources().getColor(R.color.white))
                .setTextColorCenter(mContext.getResources().getColor(R.color.theme_color_0))
                .setOutSideCancelable(true)//点击屏幕，点在控件外部范围时，是否取消显示
                .isRestoreItem(true)//切换时是否还原，设置默认选中第一项。
                .isCenterLabel(false) //是否只显示中间选中项的label文字，false则每项item全部都带有label。
                .setOutSideColor(0x40000000) //设置外部遮罩颜色
                .build();
        mOptionsPickerView.setPicker(mOptionList);
    }

    public ZHISDailyCaseEntity getFilterResults() {

//        if (TextUtils.isEmpty(mParamsPromisedDueStartDate) && (!TextUtils.isEmpty(mParamsPromisedDueEndDate))) {
//            ToastUtil.s(getResources().getString(R.string.start_date_des));
//            return null;
//        }
//
//        if (TextUtils.isEmpty(mParamsPromisedDueEndDate) && (!TextUtils.isEmpty(mParamsPromisedDueStartDate))) {
//            ToastUtil.s(getResources().getString(R.string.end_date_des));
//            return null;
//        }

        if (TextUtils.isEmpty(mParamsStartDate) && (!TextUtils.isEmpty(mParamsEndDate))) {
            ToastUtil.s(getResources().getString(R.string.start_date_des));
            return null;
        }

        if (TextUtils.isEmpty(mParamsEndDate) && (!TextUtils.isEmpty(mParamsStartDate))) {
            ToastUtil.s(getResources().getString(R.string.end_date_des));
            return null;
        }

        mParamsOverdueDays = StringUtil.safeString(et_overdue_days.getText().toString().trim());

        if (TextUtils.isEmpty(mParamsOverdueQueryType) && (!TextUtils.isEmpty(mParamsOverdueDays))) {
            ToastUtil.s(getResources().getString(R.string.overdue_days_type_des));
            return null;
        }

        if (TextUtils.isEmpty(mParamsOverdueDays) && (!TextUtils.isEmpty(mParamsOverdueQueryType))) {
            ToastUtil.s(getResources().getString(R.string.overdue_days_des));
            return null;
        }

        ZHISDailyCaseEntity zhisDailyCaseEntity = new ZHISDailyCaseEntity();

        //TOTAL：今日总订单，ADD：今日新增订单，REPAY：今日已还）
        zhisDailyCaseEntity.setTypeOne("");
        if (StringUtil.safeString(mParamsTodayOrder).equalsIgnoreCase(tv_today_all_orders.getText().toString().trim())) {
            zhisDailyCaseEntity.setTypeOne("TOTAL");
        } else if (StringUtil.safeString(mParamsTodayOrder).equalsIgnoreCase(tv_today_new_orders.getText().toString().trim())) {
            zhisDailyCaseEntity.setTypeOne("ADD");
        } else if (StringUtil.safeString(mParamsTodayOrder).equalsIgnoreCase(tv_today_repay_orders.getText().toString().trim())) {
            zhisDailyCaseEntity.setTypeOne("REPAY");
        }

        //（NOTMARK：未催收订单，ONEMARK：只催了一次的订单，TWOMARK：只催了两次的订单）
        zhisDailyCaseEntity.setTypeTwo("");
        if (StringUtil.safeString(mParamsCallCount).equalsIgnoreCase(tv_no_call.getText().toString().trim())) {
            zhisDailyCaseEntity.setTypeTwo("NOTMARK");
        } else if (StringUtil.safeString(mParamsCallCount).equalsIgnoreCase(tv_call_once.getText().toString().trim())) {
            zhisDailyCaseEntity.setTypeTwo("ONEMARK");
        } else if (StringUtil.safeString(mParamsCallCount).equalsIgnoreCase(tv_call_twice.getText().toString().trim())) {
            zhisDailyCaseEntity.setTypeTwo("TWOMARK");
        }

        //催记类型
        zhisDailyCaseEntity.setContactResult(mParamsCallResult);

        //应还开始时间
        zhisDailyCaseEntity.setRepayStartTime(mParamsStartDate);

        //应还结束时间
        zhisDailyCaseEntity.setRepayEndTime(mParamsEndDate);

        //运算符（">"，"<"，"="）
        zhisDailyCaseEntity.setCalcType("");
        if (getResources().getString(R.string.more_than).equalsIgnoreCase(mParamsOverdueQueryType)) {
            zhisDailyCaseEntity.setCalcType(">");
        } else if (getResources().getString(R.string.equal).equalsIgnoreCase(mParamsOverdueQueryType)) {
            zhisDailyCaseEntity.setCalcType("=");
        } else if (getResources().getString(R.string.less_than).equalsIgnoreCase(mParamsOverdueQueryType)) {
            zhisDailyCaseEntity.setCalcType("<");
        }

        //逾期天数
        zhisDailyCaseEntity.setOverdueDay(mParamsOverdueDays);

        mParamsMobile = StringUtil.safeString(et_user_mobile.getText().toString().trim());
        //逾期天数
        zhisDailyCaseEntity.setMobile(mParamsMobile);

        //承诺还款开始时间
        zhisDailyCaseEntity.setPtpTimeStart(mParamsPromisedDueStartDate);

        //承诺还款结束时间
        zhisDailyCaseEntity.setPtpTimeEnd(mParamsPromisedDueEndDate);

        return zhisDailyCaseEntity;
    }
}
